package com.le.tester.javaThink.fourth.concurrency;

/**
 * createTime：2021/9/16 15:40
 * description：synchronized来解决同步问题
 */
public class SynchronizedEvenGenerator extends IntGenerator {

    //单例的那边私有构造器
    //同步的进行程序，注意私有权限
    private int currentEvenValue = 0;

    @Override
    public synchronized int next() {
        ++currentEvenValue;
        Thread.yield();
        ++currentEvenValue;
        return currentEvenValue;
    }

    public static void main(String[] args) {
        EvenChecker.test(new SynchronizedEvenGenerator());
    }
}
